

$.ajax({
    type: "get",
    url: "http://v.juhe.cn/toutiao/index",
    data: {
        type:'top',
        key:'807f10d5da886d846acdde0d7c34024d'
    },
    dataType: "json",
    success: function (response) {
        console.log(response)
        // 解析后台返回的数据
        formateData(response)
    },
    error:function(code,err){
        console.log(code,err);
    }
});


function formateData(res){
    let str = ``
    res.result.data.forEach((item,index)=>{
        str+=`
        <li onclick="gotoDetail('${item.url}')">
            <h2>${item.title}</h2>
            <div class='imgs'>
                <img src="${item.thumbnail_pic_s}" alt="">
                <img src="${item.thumbnail_pic_s02}" alt="">
                <img src="${item.thumbnail_pic_s03}" alt="">
            </div>
            <div class="footer_content">
                <div class="left">
                    <span>${item.author_name}</span>
                    <span>${item.date}</span>
                </div>
                <div class="right">
                    <span>x</span>
                </div>
            </div>
        </li>
        `
    })

    document.querySelector('ul').innerHTML=str




}


function gotoDetail(url){
    window.location.href = url
}